package response

import (
	"encoding/json"
    "strconv"
)


type UserSecKillInfo struct{
    Error   int                     `json:"error"`
    Status  int                     `json:"status"`
    GoodsId int                     `json:"goodsid"`
}

type ProductSecKillInfo struct{
    Error   int                     `json:"error"`
    List    []map[string]int     `json:"list"`
}

type SickingInfo struct{
	  Error   int                     `json:"error"`
          Status  int                     `json:"status"`
          ErrMeg  string                  `json:"errmeg"`

}

type ErrorNO struct{
		Status0 int
}


func UserSecKillInfoResponse(errno, status, goodsId int) (string, error) {
    info := &UserSecKillInfo{
        Error:   errno,
        Status: status,
        GoodsId: goodsId,
     }
    responseStr, err := json.Marshal(info)
    if err == nil {
        return string(responseStr), nil
    } else {
        return "", err
    }
}

func ProductSecKillInfoResponse(errno int, list map[string]string) (string, error){
    infoList := make([]map[string]int, 0)
    for k, v := range list {
        info := make(map[string]int)
        info["userid"], _ = strconv.Atoi(k)
        info["goodsid"], _ = strconv.Atoi(v)
        infoList = append(infoList, info)
    }
    info := &ProductSecKillInfo{
        Error:  errno,
        List: infoList,
    }
    responseStr, err := json.Marshal(info)
    if err == nil {
        return string(responseStr), nil
    } else {
        return "", err
    }
}

func SecKill(errno int, status int,  errmeg string) (string, error) {
    info := &SickingInfo{
        Error:   errno,
        Status: status,
        ErrMeg: errmeg,
     }
    responseStr, err := json.Marshal(info)
    if err == nil {
        return string(responseStr), nil
    } else {
        return "", err
    }
}
